/******************************************************************************
*  COPYRIGHT MorningCore CO.,LTD
******************************************************************************/

/*****************************************************************
 * FileName::    RSGen.c
 * version::     1.0.0
 * Purpose:      Cyclic shifted sequence generation for PUCCH DMRS
 * Authors:      xiongfang, 2013-12-18
 * Notes:        None
 ******************************************************************/

/******************************************************************************
*  HISTORY OF CHANGES
*   <Date>          <Author>        <Version>       <DESCRIPTION>
*   2013-12-18      xiongfang       V0.0.1           original
******************************************************************************/

/******************************************************************************
*  INCLUDE FILES
******************************************************************************/
#include <stdio.h>
#include <math.h>
#include "../../../CommLib_FltC/Typedef.h"
#include "../../../CommLib_FltC/Common_function.h"
#include "../common/head/NR_UL_macro.h"

/*----------- function definition-----------------------------------*/
/*****************************************************************************
* Function: RSGen_PUCCH()
* Purpose:  This function performs cyclic shift sequence generation for PUCCH
*
* Relation:
            Calls       : ....
            Called by   : ....
* Params:
*   <Name>                  <Type>      <In/Out>    <Description>
*   ZCRootSeqGen_Op[PUCCH_Max_RE]   cmplx_frN   In          Zadoff-Chu root sequence
*   RootSeqLen              int         In          length of root seq
*   RS_SC_Num               int         In          number of sub-carriers of RS
*   PUCCH_RS_Ncs            int         In          Cyclic shift param of PUCCH in 3GPP TS 36.211,
*   SeqIdx                  int         In          Sequence index for short base seq
*   RS_Type                 int         In          0: DMRS/PRACH ;1:SRS
*   N_RotateCoef            int8        In          processing bit width
*   PUCCH_TxPort_Index      int8        In          PUCCH Txport index
*   RSGen_Op[PUCCH_Max_RE]          cmplx_frN   Out         output of RSGen for PUCCH

* Return:  void
* Note:    None
*******************************************************************************/
//extern FILE *fp_temp;
void RSGen_PUCCH_fix
(
    int8    PUCCH_RB_Num,
    int8    SlotIdx,
    int     ScrambID,
    int8    FirstSym_Pos,
    int8    N_PUCCH_SYM,
    cmplx_frN  RSGen_Op[PUCCH_Max_RE]
)   // output of RSGen
{
    uint32   CiniForPUCCH;
    uint32  x1,x2;
	int32   i;
	//int8	val;
	//int8  c;
	cmplx_frN  DMRS_QAM;
	int  DMRSlen;
	DMRSlen = 4*273;//



	//CiniForPUCCH = ((((14*SlotIdx+(FirstSym_Pos+N_PUCCH_SYM)+1)*(2*ScrambID+1))<<17)+2*ScrambID)%(1<<31);
	CiniForPUCCH = ((((14*SlotIdx+(FirstSym_Pos+N_PUCCH_SYM)+1)*(2*ScrambID+1))<<17)+2*ScrambID)&(0x7fffffff);


	x1 = 0;

	if(0 == x1)//First symbol need to calculate Initial sequence, initial x1 = 0 outside
	{
		vRsSkipPreNum_ul(CiniForPUCCH, &x1,&x2);
	}


	for(i=0; i<DMRSlen; i++)
	{	
		vRandBitToRsSym_PUCCH_fix(x1, x2, &DMRS_QAM);
		RSGen_Op[i] = DMRS_QAM;
		vRsGetNextNum(&x1, &x2);//re
		vRsGetNextNum(&x1, &x2);//im
	}


}



